import request from '@/utils/request'
import type { RoleResponseData, AclRole, MenuResponseData } from './type'
export const reqRoleList = (page: number, limit: number, roleName: string) => {
  return request.get<any, RoleResponseData>(
    `/admin/acl/role/${page}/${limit}?roleName=${roleName}`,
  )
}

export const reqRoleAddOrUpdate = (data: AclRole) => {
  if (data.id) {
    return request.put<any, any>('/admin/acl/role/update', data)
  } else {
    return request.post<any, any>('/admin/acl/role/save', data)
  }
}

export const reqRoleMenuList = (roleId: number) =>
  request.get<any, MenuResponseData>(`/admin/acl/permission/toAssign/${roleId}`)

export const reqRolePermission = (roleId:number,permissionId:number[]) => {
  return request.post<any,any>(`/admin/acl/permission/doAssign?roleId=${roleId}&permissionId=${permissionId}`)
}

export const reqDeleteRole = (id: number) =>
  request.delete<any, any>(`/admin/acl/role/remove/${id}`)